package org.darcy.service.check.impl;

import java.util.List;

import org.darcy.dao.CheckLibAnalysisMapper;
import org.darcy.entity.CheckCollect;
import org.darcy.entity.CheckDelivery;
import org.darcy.entity.CheckLibAnalysis;
import org.darcy.framework.constant.SysConstant;
import org.darcy.framework.generic.GenericServiceImpl;
import org.darcy.framework.model.PageData;
import org.darcy.framework.model.PageParam;
import org.darcy.service.check.CheckCollectService;
import org.darcy.service.check.CheckLibAnalysisService;
import org.darcy.service.work.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * CheckLibAnalysis服务实现
 */
@Service
@Transactional
public class CheckLibAnalysisServiceImpl extends GenericServiceImpl<CheckLibAnalysis>
		implements CheckLibAnalysisService {

	@Autowired
	private CheckLibAnalysisMapper mapper;

	@Autowired
	private CheckCollectService CheckCollectService;
	
	@Autowired
	private WorkService WorkService;
	
	/**
	 * 处理工作任务
	 */
	private void processWork(CheckLibAnalysis record) {
		// 生成审批任务
		WorkService.addWorkTask(record, null, null, SysConstant.FormType.LibAnalysis);
	}
	
	@Override
	public CheckLibAnalysis update(CheckLibAnalysis record) {
		super.update(record);
		processWork(record);
		return record;
	}

	@Override
	public CheckLibAnalysis getDetail(Integer id) {
		CheckLibAnalysis record = mapper.selectById(id);
		record.setCollect(CheckCollectService.getDetailProgress(record.getCheckId(), SysConstant.FormType.LibAnalysis));
		return record;
	}

	@Override
	public PageData<CheckLibAnalysis> page(PageParam param) {
		PageData<CheckLibAnalysis> data = super.getPageData(param);
		return data;
	}

	@Override
	public List<CheckLibAnalysis> getList(Integer checkId) {
		QueryWrapper<CheckLibAnalysis> q = new QueryWrapper<CheckLibAnalysis>();
		q.eq("check_id", checkId);
		return this.getList(q);
	}

}
